package csx.study.demo.utils;


import csx.study.demo.dto.UserDTO;

//封装到UserHolder里是一种最佳实践
public class UserHolder {
    //TODO 搞懂ThreadLocal，为什么要静态，为什么要用ThreadLocal
    //TODO 为什么要放到UserHolder里
    private static final ThreadLocal<UserDTO> tl = new ThreadLocal<>();

    public static void saveUser(UserDTO user){
        tl.set(user);
    }

    public static UserDTO getUser(){
        return tl.get();
    }

    public static void removeUser(){
        tl.remove();
    }
}
